<?php
class classArticle{
    public function getUserArticle(){
        //retrieve data from URL
        $_URL           = new classURL();
        $_AS            = new classArticleService();
        $sURLMenuValue 	= $_URL->GetMenu();
        $iArticleType   = $_URL->GetValueFromURL($sURLMenuValue, 'a_type');
        $iArticleID     = $_URL->GetValueFromURL($sURLMenuValue, 'a_text');
        $result         = '';
        $part_url_array = explode(_URL_VAL_DELIMITER_,$sURLMenuValue);

        //show article
        if(
            is_numeric($iArticleType) and ($iArticleType>0) and
            is_numeric($iArticleID) and ($iArticleID>0)             
        ){

            if($iArticleType==1 and !$_AS->newsExists($iArticleID)) return '';
            if($iArticleType==2 and !$_AS->articleExists($iArticleID)) return '';

            $_Window = new classWindow();
            $_URL = new classURL();
            //$URL_of_Product = $_URL->GetProduct();
            $CloseURL = $_URL->SetURL('','keep_value', '');
            $result .= $_Window->ShowByURL($this->GetArticleText($iArticleType, $iArticleID),$CloseURL);
        }
        	
        return $result;
    }
    
    
    private function GetArticleText($sArticleType, $sID){
        //sArticle types list:
        //"1" - top menu, news
        //"2" - top menu, users artiles - users defined top menu
        
        
        $sArticlesCaption = '';
        $sArticlesText = '';
        
        if($sArticleType==1) $this->getArticleOfNews($sID, $sArticlesCaption, $sArticlesText);
        if($sArticleType==2) $this->getArticleOfUsersTopMenu($sID, $sArticlesCaption, $sArticlesText);
        
        //product form from template
        $_Skin = new classTemplate();
        $result = '';
        include $_Skin->getActual().'/article.inc.php';       
        
        return $result;        
    }
    
    private function getArticleOfNews($sID,&$sArticlesCaption,&$sArticlesText){
        $sql_result = mysql_query('
            SELECT 
              News_Caption, Value 
            FROM 
              top_menu_news, top_menu_text
            WHERE(
              top_menu_news.ID = '.$sID.' AND
              top_menu_news.ID = top_menu_text.Type_ID AND
              top_menu_text.Type="NEWS"
            )              
        ');
        $sql_obj = mysql_fetch_object($sql_result);
        
        $sArticlesCaption = $sql_obj->News_Caption;
        $sArticlesText = $sql_obj->Value;
    }
    
    private function getArticleOfUsersTopMenu($sID,&$sArticlesCaption,&$sArticlesText){
        $sql_result = mysql_query('
            SELECT 
              SC_Caption, Value 
            FROM 
              top_menu_sub_category , top_menu_text
            WHERE(
              top_menu_sub_category .ID = '.$sID.' AND
              top_menu_sub_category .ID = top_menu_text.Type_ID AND
              top_menu_text.Type="MENU"
            )              
        ');
        $sql_obj = mysql_fetch_object($sql_result);
        
        $sArticlesCaption = $sql_obj->SC_Caption;
        $sArticlesText = $sql_obj->Value;
    }
}
?>
